<?php

# PMB Online
# Aplikasi Web Dosen di PT/PTS Indonesia
# 
# version 1.0
# class graph
# file
# created Feb 19, 2013 6:40:49 PM
# 
# (c)2012, arif.laksito@gmail.com

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Cgraph extends CI_Controller {

    public function pie_mhs() {

        $this->load->library('jpgraph');
        $this->jpgraph->pie();

        $this->load->model('csiswa');
        $data = $this->csiswa->count_siswa_gel();

        $graph = new PieGraph(500, 500);
        $graph->SetShadow();

        $size = 0.13;

        $i = 0;
        foreach ($data as $d) {
            if ($d['nlulus'] > 0 && $d['lulus'] > 0) {
                $p1 = new PiePlot(array($d['nlulus'],$d['lulus']));
                $graph->Add($p1);

                $p1->SetSize($size);

                if ($i == 0)
                    $p1->SetCenter(0.25, 0.32);
                if ($i == 1)
                    $p1->SetCenter(0.65, 0.32);
                if ($i == 2)
                    $p1->SetCenter(0.25, 0.75);
                if ($i == 3)
                    $p1->SetCenter(0.65, 0.75);

                $p1->SetSliceColors(array('#0061ae', '#fbb249'));
                $p1->SetLegends(array('Blm Lulus','Lulus'));
                $p1->title->Set($d['gel']);
                $i++;
            }
        }

        $graph->Stroke();
    }
    
    public function bar_mhs(){
        $this->load->library('jpgraph');
        $this->jpgraph->bar();
        
        $graph = new Graph(500,280,'auto');
        $graph->SetScale("textint");
        
        $this->load->model('csiswa');
        $data = $this->csiswa->count_siswa_gel();
        
        $d1 = array();
        $d2 = array();
        $label = array();
        foreach($data as $d){
            $d1[] = $d['lulus'];
            $d2[] = $d['nlulus'];
            $d3[] = $d['tlulus'];
            $label[] = $d['gel'];
        }
        
        $theme_class=new UniversalTheme;
        $graph->SetTheme($theme_class);
        
        $graph->ygrid->SetFill(false);
        $graph->xaxis->SetTickLabels($label);
        $graph->yaxis->HideLine(false);
        $graph->yaxis->HideTicks(false,false);
        
        $b1plot = new BarPlot($d1);
        $b2plot = new BarPlot($d2);
        $b3plot = new BarPlot($d3);
        
        $gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));
        $graph->Add($gbplot);
        
        $b1plot->SetColor("white");
        $b1plot->SetFillColor("#cc1111");
        $b1plot->SetLegend("Lulus");

        $b2plot->SetColor("white");
        $b2plot->SetFillColor("#11cccc");
        $b2plot->SetLegend("Blm Lulus");
        
        $b3plot->SetColor("white");
        $b3plot->SetFillColor("#1111cc");
        $b3plot->SetLegend("Tidak Lulus");
        
        $graph->Stroke();
        
    }
    
    public function bar_ol(){
        $this->load->library('jpgraph');
        $this->jpgraph->bar();
        
        $graph = new Graph(500,280,'auto');
        $graph->SetScale("textint");
        
        $this->load->model('csiswa');
        $data = $this->csiswa->count_siswa_ol();
        
        $d1 = array();
        $d2 = array();
        $label = array();
        foreach($data as $d){
            $d1[] = $d['ol'];
            $d2[] = $d['off'];
            $label[] = $d['gel'];
        }
        
        $theme_class=new UniversalTheme;
        $graph->SetTheme($theme_class);
        
        $graph->ygrid->SetFill(false);
        $graph->xaxis->SetTickLabels($label);
        $graph->yaxis->HideLine(false);
        $graph->yaxis->HideTicks(false,false);
        
        $b1plot = new BarPlot($d1);
        $b2plot = new BarPlot($d2);
        
        $gbplot = new GroupBarPlot(array($b1plot,$b2plot));
        $graph->Add($gbplot);
        
        $b1plot->SetColor("white");
        $b1plot->SetFillColor("#cc11cc");
        $b1plot->SetLegend("Online");

        $b2plot->SetColor("white");
        $b2plot->SetFillColor("#11cc11");
        $b2plot->SetLegend("Offline");
        
        $graph->Stroke();
    }
    
    public function bar_asal(){
        $this->load->library('jpgraph');
        $this->jpgraph->bar();
        
        $graph = new Graph(500,280,'auto');
        $graph->SetScale("textint");
        
        $this->load->model('csiswa');
        $data = $this->csiswa->count_asal();
        
        $d1 = array();
        $lb = array();
        foreach($data as $d){
            $d1[] = $d['jml'];
            $lb[] = $d['sekolah_asal'];
        }
        
        $theme_class=new UniversalTheme;
        $graph->SetTheme($theme_class);
        
        $graph->ygrid->SetFill(false);
        $graph->xaxis->SetTickLabels($lb);
        $graph->yaxis->HideLine(false);
        $graph->yaxis->HideTicks(false,false);
        
        $b1plot = new BarPlot($d1);                        
        $graph->Add($b1plot);
        
        $b1plot->SetColor("white");
        $b1plot->SetFillColor("#11cccc");        
        
        $graph->Stroke();
    }
    
    public function bar_info(){
        $this->load->library('jpgraph');
        $this->jpgraph->bar();
        
        $graph = new Graph(500,280,'auto');
        $graph->SetScale("textint");
        
        $this->load->model('csiswa');
        $data = $this->csiswa->count_info();
        
        $d1 = array();
        $lb = array();
        foreach($data as $k=>$d){
            $d1[] = $d;
            $lb[] = $k;
        }
        
        $theme_class=new UniversalTheme;
        $graph->SetTheme($theme_class);
        
        $graph->ygrid->SetFill(false);
        $graph->xaxis->SetTickLabels($lb);
        $graph->yaxis->HideLine(false);
        $graph->yaxis->HideTicks(false,false);
        
        $b1plot = new BarPlot($d1);                        
        $graph->Add($b1plot);
        
        $b1plot->SetColor("white");
        $b1plot->SetFillColor("#cccc11");        
        
        $graph->Stroke();
    }
}